<template>
  <div class="custom-form">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px"
        :key="showFormKey">
        <!-- 外派申请 -->
        <el-col :span="24">
          <el-form-item label-width="0" prop="field100674f">
            <h2 align='center' style="color:undefined;font-size: nullpx;text-align: center">外派申请</h2>
          </el-form-item>
        </el-col>
        <!-- 角色ID -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('角色ID')" prop="F_RoleId">
            <el-input v-model="formData['F_RoleId']" 
            :readonly="true"
            placeholder="请输入角色ID" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 角色名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('角色名称')" prop="F_RoleName">
            <el-input v-model="formData['F_RoleName']" 
            :readonly="true"
            placeholder="请输入角色名称" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 地区 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('地区')" prop="F_Area">
            <el-input v-model="formData['F_Area']" 
            :readonly="true"
            placeholder="请输入地区" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 职级名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('职级名称')" prop="F_Job">
            <el-input v-model="formData['F_Job']" 
            :readonly="true"
            placeholder="请输入职级名称" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 部门名称 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('部门名称')">
            <el-input v-model="formData['F_DepartmentName']" placeholder="请输入部门名称" :readonly="true" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 部门ID -->
        <el-col :span="24">
          <el-form-item :label="$t('部门')" prop="F_DepartmentId">
            <el-select
              v-model="formData['F_DepartmentId']"
              placeholder="请选择部门"
              filterable
              clearable
              @change="selectDepartMent"
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in F_DepartmentData"
                :key="index"
                :label="item.F_FullName"
                :value="item.F_DepartmentId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 申请人ID -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('申请人ID')" prop="F_UserId">
            <el-input v-model="formData['F_UserId']" placeholder="请输入申请人ID" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 申请人姓名 -->
        <el-col :span="24">
          <el-form-item :label="$t('申请人姓名')" prop="F_UserName">
            <el-input :readonly="true" v-model="formData['F_UserName']" placeholder="请输入申请人姓名" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 申请时间 -->
        <el-col :span="24" v-show="showFlag">
          <el-form-item :label="$t('申请时间')" prop="F_CreateTime">
            <el-input v-model="formData['F_CreateTime']" 
            :readonly="true"
            placeholder="请输入申请时间" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 外派考勤组 -->
        <el-col :span="24">
          <el-form-item :label="$t('外派考勤组')" prop="F_AttendanceGroupId">
            <el-select v-model="formData['F_AttendanceGroupId']" placeholder="请选择外派考勤组"
              :disabled="hasDisabledPermission('F_AttendanceGroupId',false)" filterable clearable @change="selectAttendanceGroup"
              :style="{width: '100%'}">
              <el-option v-for="(item, index) in F_AttendanceGroupIdOptions" :key="index" :label="item.group_name"
                :value="item.F_Id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 外派考勤组组长 -->
        <el-col :span="24" >
          <el-form-item :label="$t('外派考勤组组长')" prop="F_Expatriate_Group_Manager_Id">
            <el-input v-model="formData['F_Expatriate_Group_Manager_Id']" placeholder="请输入外派考勤组组长" 
             :disabled="true" :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 开始时间 -->
        <el-col :span="24">
          <el-form-item :label="$t('开始时间')" prop="F_StartTime">
            <el-date-picker :disabled="hasDisabledPermission('F_StartTime',false)"
              :readonly="!hasEditPermission('F_StartTime',false)" type="datetime"
              v-model="formData['F_StartTime']" format="yyyy-MM-dd HH:mm:ss"
              @blur="getLeaveDay"
              value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" placeholder="请选择开始时间" clearable>
            </el-date-picker>
          </el-form-item>
        </el-col>
        <!-- 结束时间 -->
        <el-col :span="24">
          <el-form-item :label="$t('结束时间')" prop="F_EndTime">
            <el-date-picker :disabled="hasDisabledPermission('F_EndTime',false)"
              :readonly="!hasEditPermission('F_EndTime',false)" type="datetime"
              @blur="getLeaveDay"
              v-model="formData['F_EndTime']" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
              :style="{width: '100%'}" placeholder="请选择结束时间" clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <!-- 外派时长 -->
        <el-col :span="24">
          <el-form-item :label="$t('外派时长')" prop="F_Counts">
            <el-input v-model="formData['F_Counts']" placeholder="请输入外派时长"
              :readonly="true" clearable :style="{width: '100%'}">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 外派原因 -->
        <el-col :span="24">
          <el-form-item :label="$t('外派原因')" prop="F_Reasons">
            <el-input v-model="formData['F_Reasons']" type="textarea" placeholder="请输入外派原因"
              :disabled="hasDisabledPermission('F_Reasons',false)"
              :readonly="!hasEditPermission('F_Reasons',false)" :autosize="{minRows: 4, maxRows: 4}"
              :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <!-- 上传附件 -->
        <el-col :span="24">
          <el-form-item :label="$t('上传附件')" prop="F_FileUrl">
            <xjr-custom-upload :config="F_FileUrlConfig"
              :disabled="hasDisabledPermission('F_FileUrl',false)" v-model="formData['F_FileUrl']"
              list-type="text"></xjr-custom-upload>
          </el-form-item>
        </el-col>
        <!-- 已生效 -->
        <el-col :span="24" v-show="showFlag" >
          <el-form-item :label="$t('已生效')" prop="F_IsEffective">
            <el-input v-model="formData['F_IsEffective']" placeholder="请输入已生效"
              :disabled="hasDisabledPermission('F_IsEffective',false)"
              :readonly="!hasEditPermission('F_IsEffective',false)" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <!-- 意见簿 -->
        <el-col :span="24" v-show="optionsFlag">
          <el-form-item :label="$t('意见簿')" prop="field11038bf">
            <xjr-opinion-comonent :value="formData.field11038bf"></xjr-opinion-comonent>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!isWorkflowForm">
          <el-form-item size="large" v-if="isEdit">
            <el-button type="primary" @click="submitForm" :loading="submitLoading">
              {{submitLoading?$t('workFlow.WFMenu.hintSubmit'):$t('submit')}}</el-button>
            <el-button @click="cancelForm">{{$t('cancelText')}}</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>

  import FilterableDataList from '@/components/generator/clientComponents/FilterableDataList.vue';
  import workflowFormAuthorize from "@/mixins/workflowFormAuthorize";
  import authorizeMixin from "@/mixins/authorize";
  import { baseUrl } from "@/config/env";
  import request from "@/router/axios";
  import {getAttendanceGroupList,getLeaveDay,getUserDetailsById} from '@/api/user.js';
  export default {
    mixins: [authorizeMixin,workflowFormAuthorize],
  components: {},
  props: ['keyValue', 'isEdit', 'disabled'],
  data() {
    let _this = this
    return {
      submitLoading: false,
      showForm: true,
      showFormKey: 1,
      reRenderSubform: false,
      operationVal: 'add',
      isAdd: true,
      addressUrl:'expatriate',
      mainTableName: 'oa_expatriate',
      formConfig: {},
      formData: {
        'field100674f': '',
        'F_DepartmentId': '',
        'F_UserId': '', // 申请人id
        'F_AttendanceGroupId': '',
        'F_StartTime': null,
        'F_EndTime': null,
        'F_Counts': '',
        'F_Reasons': '',
        'F_FileUrl': null,
        'F_IsEffective': "0",
        'field11038bf': null,
        'F_Expatriate_Group_Manager_Id':'',//外派考勤组组长
        'F_RoleId': '', //角色id
        'F_RoleName': '', //角色名称
        'F_Area': '', //地区
        'F_Job': '', //职级名称
        'F_DepartmentName': '', //部门名称
        'F_UserName': '', //申请人姓名
        'F_CreateTime':'2022-12-22'//申请时间
      },
      rules: {
        F_DepartmentId: [{
          required: true,
          message: '请选择部门',
          trigger: 'change'
        }],
        F_AttendanceGroupId: [{
          required: false,
          message: '请选择外派考勤组',
          trigger: 'change'
        }],
        F_StartTime: [{
          required: true,
          message: '请选择开始时间',
          trigger: 'change'
        }],
        F_EndTime: [{
          required: true,
          message: '请选择结束时间',
          trigger: 'change'
        }],
        F_Counts: [{
          required: true,
          message: '请输入外派时长',
          trigger: 'blur'
        }],
        F_Reasons: [{
          required: true,
          message: '请输入外派原因',
          trigger: 'blur'
        }],
        F_FileUrl: [],
        F_IsEffective: [{
          required: true,
          message: '请输入已生效',
          trigger: 'blur'
        }],
      },
      F_AttendanceGroupIdOptions: [],
      F_FileUrlConfig: {
        "showTip": false,
        "fileSize": 2,
        "sizeUnit": "MB",
        "buttonText": "点击上传",
        "disabled": false
      },
      F_DepartmentData:[],
      showFlag:false
    }
  },
  computed: {},
  watch: {},
  async created() {
   this.formConfig = this.getFormConfig();
  },
  async mounted() {
    //TODO   再这里做数据回填 请求表单数据
    if(this.keyValue){
        this.isAdd = false;
    }
    if(!this.isAdd&&this.keyValue){
      this.operationVal = 'edit';
      let res = await request({
        url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
        method: "get",
      });
      this.formData = res.data.data
      this.showFormKey++;
      this.formId = this.formData.F_UserId
    } 
    this.getSchedualGroupList()
    this.getUserInfo()
  },
  methods: {
    getFormData() {
      let key = this.mainTableName + 'Entity';
      let returnParams = {};
      returnParams[key] = this.formData;
      return {
        ...returnParams,
      };
    },
    validateForm() {
      this.$refs['elForm'].validate(valid => {});
    },
    async aysncValidateForm() {
      let validataArry = []
      validataArry.push(new Promise((resolve, reject) => {
        this.$refs['elForm'].validate(valid => {
          resolve(valid)
        })
      }))
      let res = await Promise.all(validataArry)
      if (res.includes(false)) {
        return false
      }
      else {
        return true;
      }
    },
    changeTableData() {},
    async submitForm() {
      this.submitLoading = true;
      let valid = await this.aysncValidateForm();
      if (valid == false) {
        this.submitLoading = false;
        return false;
      }
      this.changeTableData();
      //格式化数据
      let newObj = this.getFormData();
        //如果没有传入参数就是新增
        if (!this.keyValue) {
          request({
            url: baseUrl + "/"+this.addressUrl,
            method: "post",
            data : newObj
          }).then((res) => {
            this.submitLoading = false;
            this.$notify({
              title: "成功",
              message: "新增成功",
              type: "success",
            });
             this.$emit("onChange",true)
          }).catch((msg) => {
            this.submitLoading = false;
          });
        }
        else{
         request({
            url: baseUrl + "/"+this.addressUrl+"/" + this.keyValue,
            method: "put",
            data : newObj
          }).then((res) => {
            this.submitLoading = false;
            this.$notify({
              title: "成功",
              message: "修改成功",
              type: "success",
            });
             this.$emit("onChange",true)
          });
        }  
    },
    cancelForm() {
      this.$emit("onChange", true)
    },
    formatTree(data, valueField, lableField, childField, type) {
      let tree = [];
      data.forEach((node, index) => {
        let newNode = {
          value: node[valueField],
          label: node[lableField],
        };
        if (type) {
          newNode.disabled = node[valueField] == undefined ? true : false
        }
        tree.push(newNode);
        if (node[childField] != null && node[childField].length > 0) {
          newNode.children = (this.formatTree(node[childField], valueField, lableField, childField,
          type));
        }
      }, this);
      return tree;
    },
    //辅助工作流 审批(编辑) 预留方法
    handleEdit() {
    },
    //子表单权限
    getAuthorityTableChildrenList(bindTable, children) {
      let column = [];
      if (bindTable && this.formEnCodeList && this.formEnCodeList[bindTable]) {
        let formSubEnCodeList = this.formEnCodeList[bindTable];
        if (children && children.length > 0) {
          column = children.map(ele2 => {
            if (formSubEnCodeList.includes(ele2.prop)) {
              ele2.hide = false;
            }
            else {
              ele2.hide = true;
            }
            if (ele2.hide == false) {
              //工作流中系统表单必填权限
              if (this.formSubTableNotRequiredList[bindTable] != undefined) {
                if (this.formSubTableNotRequiredList[bindTable].includes(ele2.prop)) {
                  ele2.required = false;
                }
                else {
                  ele2.required = true;
                }
              }
              ele2.rules = [];
              if (ele2.required) {
                ele2.rules = ele2.ruleList;
              }
              // disabled 属性
              if (this.formSubTableDisabledList[bindTable] != undefined) {
                if (this.formSubTableDisabledList[bindTable].includes(ele2.prop)) {
                  ele2.disabled = true;
                }
                else {
                  ele2.disabled = false;
                }
              }
            }
            return ele2;
          });
        }
        return column;
      }
      else {
        return children;
      }
    },
    getFormConfig() {
      let config = {
        "fields": [
        // 标题
        {
          "__vModel__": "field100674f",
          "__config__": {
            "label": "外派申请",
            "showLabel": false,
            "titleColor": null,
            "fontSize": null,
            "tag": "h2",
            "span": 24,
            "align": "top",
            "justify": "start",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 100
          }
        }, 
        //角色id
        {
          "__vModel__": "F_RoleId",
          "__config__": {
            "label": "角色id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 136,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_RoleId",
            "bindTableFieldType": "varchar"
          }
        },
        //角色名称
        {
          "__vModel__": "F_RoleName",
          "__config__": {
            "label": "角色名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 135,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_RoleName",
            "bindTableFieldType": "varchar"
          }
        },
        //地区
        {
          "__vModel__": "F_Area",
          "__config__": {
            "label": "地区",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 134,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_Area",
            "bindTableFieldType": "varchar"
          }
        },
        // 部门id
        {
          "__vModel__": "F_DepartmentId",
          "__type__": "info",
          "infoType": "department",
          "__organize__": true,
          "__config__": {
            "label": "所在部门",
            "showLabel": true,
            "tag": "avue-information-body",
            "avueType": "information-body",
            "defaultValue": "aebcb1b5e8f40ffc5f2b1bee84ffecd2",
            "required": true,
            "span": 24,
            "whetherToRebindSecondaryEditing": false,
            "bindTableField": "F_DepartmentId",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 101,
            "placeholder": "当前部门",
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableFieldType": "varchar"
          }
        }, 
         //部门名称
        {
          "__vModel__": "F_DepartmentName",
          "__config__": {
            "label": "部门名称",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 132,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_DepartmentName",
            "bindTableFieldType": "varchar"
          }
        },
        //申请人id
        {
          "__vModel__": "F_UserId",
          "__config__": {
            "label": "申请人id",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 130,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_UserId",
            "bindTableFieldType": "varchar"
          }
        }, 
        //申请人姓名
        {
          "__vModel__": "F_UserName",
          "__config__": {
            "label": "申请人姓名",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": false,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 131,
            "fieldLength": 500,
            "bindTable": "oa_expatriate",
            "bindTableField": "F_UserName",
            "bindTableFieldType": "varchar"
          }
        },
        {
            "tempType": "datetime",
            "__vModel__": "F_CreateTime",
            "__config__": {
              "label": "申请时间",
              "tag": "el-date-picker",
              "avueType": "datetime",
              "defaultValue": null,
              "showLabel": true,
              "span": 24,
              "required": false,
              "F_LgMarkCode": "",
              "prestrainField": "",
              "formId": 158,
              "fieldLength": 500,
              "bindTableFieldType": "datetime",
              "bindTable": "oa_expatriate",
              "bindTableField": "F_CreateTime"
            }
        }, 
        //职级
        {
            "__vModel__": "F_Job",
            "__config__": {
              "label": "职级",
              "showLabel": true,
              "tag": "el-input",
              "avueType": "input-tip",
              "required": false,
              "span": 24,
              "F_LgMarkCode": "",
              "prestrainField": "",
              "formId": 137,
              "fieldLength": 500,
              "bindTable": "oa_expatriate",
              "bindTableField": "F_Job",
              "bindTableFieldType": "varchar"
            }
        }, 
        //外派考勤组组长
        {
            "__vModel__": "F_Expatriate_Group_Manager_Id",
            "__config__": {
              "label": "外派考勤组组长",
              "showLabel": true,
              "tag": "el-input",
              "avueType": "input-tip",
              "required": false,
              "span": 24,
              "F_LgMarkCode": "",
              "prestrainField": "",
              "formId": 138,
              "fieldLength": 50,
              "bindTable": "oa_expatriate",
              "bindTableField": "F_Expatriate_Group_Manager_Id",
              "bindTableFieldType": "varchar"
            }
        }, 
        {
          "__vModel__": "F_AttendanceGroupId",
          "__config__": {
            "label": "外派考勤组",
            "showLabel": true,
            "tag": "el-select",
            "avueType": "select",
            "span": 24,
            "required": true,
            "saveField": "",
            "showField": "",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 103,
            "fieldLength": "50",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_AttendanceGroupId",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "datetime",
          "__vModel__": "F_StartTime",
          "__config__": {
            "label": "开始时间",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 104,
            "fieldLength": "50",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_StartTime"
          }
        }, {
          "tempType": "datetime",
          "__vModel__": "F_EndTime",
          "__config__": {
            "label": "结束时间",
            "tag": "el-date-picker",
            "avueType": "datetime",
            "defaultValue": null,
            "showLabel": true,
            "span": 24,
            "required": true,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 105,
            "fieldLength": "50",
            "bindTableFieldType": "datetime",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_EndTime"
          }
        }, {
          "__vModel__": "F_Counts",
          "append": "天",
          "__config__": {
            "label": "外派时长",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 106,
            "fieldLength": "10",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_Counts",
            "bindTableFieldType": "varchar"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "F_Reasons",
          "__config__": {
            "label": "外派原因",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "textarea",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 107,
            "fieldLength": "500",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_Reasons",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_FileUrl",
          "__config__": {
            "label": "上传附件",
            "tag": "el-upload",
            "avueType": "upload",
            "defaultValue": null,
            "showLabel": true,
            "required": false,
            "span": 24,
            "showTip": false,
            "buttonText": "点击上传",
            "fileSize": 2,
            "sizeUnit": "MB",
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 108,
            "fieldLength": "500",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_FileUrl",
            "bindTableFieldType": "varchar"
          }
        }, {
          "__vModel__": "F_IsEffective",
          "__config__": {
            "label": "已生效",
            "showLabel": true,
            "tag": "el-input",
            "avueType": "input-tip",
            "defaultValue": "0",
            "required": true,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 109,
            "fieldLength": "2",
            "bindTable": "oa_expatriate",
            "bindTableField": "F_IsEffective",
            "bindTableFieldType": "int"
          }
        }, {
          "tempType": "textarea",
          "__vModel__": "field11038bf",
          "__type__": "opinion",
          "__config__": {
            "label": "意见簿",
            "showLabel": true,
            "tag": "xjr-opinion-comonent",
            "defaultValue": null,
            "span": 24,
            "F_LgMarkCode": "",
            "prestrainField": "",
            "formId": 110
          }
        }]
      };
      return config;
    },
    getSchedualGroupList(){
      let params = {
        order:'desc',
        orderfield:'create_time',
        schedual_group_name:"",
        limit:1,
        size:100,
      }
      getAttendanceGroupList(params).then(res => {
        if(res && res.data && res.data.data){
          this.F_AttendanceGroupIdOptions = res.data.data.Rows
          if(this.formData['F_AttendanceGroupId']){
            this.formData['F_AttendanceGroupId'] = parseInt(this.formData['F_AttendanceGroupId'])
          }
        }
      })
    },
    getLeaveDay(){
      
      let params
      if(this.formData.F_UserId){
        params = {
          userId:this.formData.F_UserId,
          startTime:this.formData['F_StartTime'],
          endTime:this.formData['F_EndTime']
        }
      }else{
        params = {
          userId:this.$store.state.user.userInfo.F_UserId,
          startTime:this.formData['F_StartTime'],
          endTime:this.formData['F_EndTime']
        }
      }
      if(this.formData['F_StartTime'] && this.formData['F_EndTime']){
        getLeaveDay(params).then(res => {
          if(res.data && res.data.success){
            this.formData['F_Counts'] = res.data.data
          }else{
            this.$message.error("系统错误，请联系管理员")
          }
        })
      }
    },
    
    getUserInfo(){
      //判断部门有没有数据
      let params
      if(this.formData.F_UserId){
        params = {
          userId:this.formData.F_UserId
        }
      }else{
        params = {
          userId:this.$store.state.user.userInfo.F_UserId
        }
      }
      getUserDetailsById(params).then(res => {
        if(res && res.data && res.data.success){
          this.F_DepartmentData = res.data.data.F_Department
          this.F_RoleData = res.data.data.F_Role
          //赋值申请人信息
          this.formData['F_UserName'] =  res.data.data.F_RealName
          this.formData['F_UserId'] =  res.data.data.F_UserId
          this.formData['F_Area'] = res.data.data.F_Area
          this.formData['F_Job'] = res.data.data.F_Job
          this.initRoleData()
          this.initDepartmentData()
         }
      })
    },
    initDepartmentData(){
      if(this.F_DepartmentData && this.F_DepartmentData.length == 1){
        this.formData['F_DepartmentName'] = this.F_DepartmentData[0].F_FullName
        this.formData['F_DepartmentId'] = this.F_DepartmentData[0].F_DepartmentId
      }
    },
    initRoleData(){
      let roleId = []
      let roleName = []
      if(this.F_RoleData && this.F_RoleData.length > 0){
        this.F_RoleData.forEach(e => {
          roleId.push(e.F_RoleId)
          roleName.push(e.F_FullName)
        })
      }
      this.formData['F_RoleId'] = roleId.join(',')
      this.formData['F_RoleName'] = roleName.join(',')

    },
    selectDepartMent(){
      if(this.F_DepartmentData && this.F_DepartmentData.length > 0){
        this.F_DepartmentData.forEach(e => {
          if(e.F_DepartmentId == this.formData['F_DepartmentId']){
            this.formData['F_DepartmentName'] = e.F_ShortName
          }
        })
      }
    },
    selectAttendanceGroup () {
      if (this.F_AttendanceGroupIdOptions && this.F_AttendanceGroupIdOptions.length > 0) {
        this.F_AttendanceGroupIdOptions.forEach((item) => {
          if (item.F_Id == this.formData['F_AttendanceGroupId']) {
            this.formData['F_Expatriate_Group_Manager_Id'] = item.manager_name
          }
        })

      }
    }
  }
}
</script>
<style>
.el-table__empty-block {
  width: 100% !important;
}
.avue-form__row {
  padding: 0 !important;
}
#editorphone {
  width: 375px;
  margin: 0 auto;
  border: 1px solid #E4E7ED;
  padding: 0 7.5px;
  background: #f5f6fa;
  height: 700px;
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: 5px;
}
#editorphone .el-col {
  border-bottom: 1px solid #F2F2F2;
  background: #fff;
  margin-bottom: 0;
  padding: 0 15px 6px !important;
  width: 100%;
}
#editorphone .el-form-item__label {
  line-height: 20px
}
#editorphone .el-input-group .el-input__inner {
  background: #f5f6fa
}
#editorphone .el-input__inner {
  border: 0
}
#editorphone .el-input-group__append,
#editorphone .el-input-group__prepend {
  border: 0;
  background: #edeef2;
  color: #666;
}
#editorphone .el-input-group .el-input__prefix {
  left: 44px
}
#editorphone .el-input-group .el-input__suffix {
  right: 44px
}
#editorphone .el-form-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-flow: wrap;
}
#editorphone .el-form-item__label {
  float: none;
  min-width: 85px;
  width: auto !important;
  text-align: left;
  flex: auto;
}
#editorphone .tinymce .el-form-item__label {
  min-width: 100%;
}
#editorphone .el-form-item__content {
  margin-left: 0px !important;
  flex: auto;
  width: calc(100% - 95px);
}
#editorphone .avueFormNoLable .el-form-item__label,
#editorphone .avueFormNoLable .avue-crud__pagination {
  display: none;
}
#editorphone .avueFormNoLable .el-collapse-item__wrap,
#editorphone .avueFormNoLable .el-collapse {
  border-bottom: 0
}
#editorphone .avueFormNoLable .el-col {
  border-bottom: 0;
  padding-bottom: 0
}
#editorphone .el-form-item__content .el-button:first-child {
  margin-left: 90px;
}
.el-upload__tip {
  line-height: 1.2;
}
</style>
